#include <iostream>
#include "FileOptWithPoint.h"

using namespace std;
using namespace FileOpt;

FileOptWithPoint::FileOptWithPoint(const std::string& filePathName, const std::string& mode) {
#ifdef FUNC
    cout << "define FUNC" << endl;
#else
    cout << "no define FUNC" << endl;
#endif
    m_fp_ = fopen(filePathName.c_str(), mode.c_str()); 
    if(NULL == m_fp_) {
        perror("file open error");
    }
}

bool FileOptWithPoint::read(vector<char>& buf, const uint32_t readSize ) {
    if(NULL == fgets(buf.data(), readSize, m_fp_)) {
        return false;
    }   
    return true;
}

bool FileOptWithPoint::write(const vector<char>& buf) {
    if(EOF == fputs(buf.data(),  m_fp_)) {
        return false;
    }
    return true;
}

FileOptWithPoint::~FileOptWithPoint() {
    if(NULL == m_fp_) {
        return ;
    }
    if(fclose(m_fp_)) {
        perror("file close error:");
    }
}
